<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/20
 * Time: 10:52
 */
namespace app\badminton\controller;

use app\badminton\model\AdminRoleGroup;
use app\badminton\model\AdminRule;
use think\Request;

class Group extends BassController{

    /**
     *  角色管理--列表
     */
    public function role_list(){

        $role_list = AdminRoleGroup::all();

        return view('',['role_list'=>$role_list]);

    }

    /**
     * 角色添加修改
     */
    public function role(){

        if(request()->isPost()){
            $data = \request()->post();
            $data['rules'] = implode(',',$data['ids']);
            unset($data['ids']);
            $obj = new AdminRoleGroup();
            if(empty($data['id'])){
                $res = $obj->allowField(true)->save($data);
            }else{
                $res = $obj->allowField(true)->save($data,$data['id']);
            }
            if($res){
                return_json(1,'操作成功');
            }else{
                return_json(0,'操作失败');
            }
        }
        $id = intval(Request::instance()->param('id'));
        $one = AdminRoleGroup::where('id',$id)->find();
        //查询顶级分类 p_id=0
        $list = AdminRule::where('p_id',0)->select();
        $result = [];
        foreach ($list as $k=>$v){
            $result[$v['title']] = AdminRule::where('p_id',$v['id'])->select();
        }
        return view('',[
            'list'=>$result,
            'one'=> $one
        ]);
    }

}